/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ik.Reposteria.SMP.Manejadores.Conectores;

import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 *
 * @author Malkavian
 */
public class ConexionMySQL {

    private static ConexionMySQL conexion;
    private static EntityManagerFactory factory = Persistence.createEntityManagerFactory("SMPPU", System.getProperties());;
    private static EntityManager entity;

    public static ConexionMySQL getInstance() {
        if (conexion == null) {
            conexion = new ConexionMySQL();
        }
        return conexion;
    }

    public ConexionMySQL() {
        if (entity == null) {
            entity = factory.createEntityManager();
        }
    }

    public static EntityManager getEntity() {
        if (!entity.isOpen() || entity == null) {
            entity = factory.createEntityManager();
        }
        return entity;
    }
}
